home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1985-11-01 | 3.5 KB | 68 lines |
- 10 ' COPYRIGHT @ 1983
- 20 ' Jim Holtman
- 30 ' 35 Dogwood Trail
- 40 ' Randolph, NJ 07869
- 50 ' (201) 361-3395
- 60 ' This sample program serves as both an example and the documentation
- 70 ' for the FCBREAD.BSV routine that will read the directory of a
- 80 ' disk and present the matching file name back to the BASIC program.
- 90 ' Also available to the program is the directory information that
- 100 ' contains the size and time/date information. This routine is
- 110 ' faster than OPENing the file since it does not incur that overhead.
- 120 ' Also the user can present an arbitrary string to match on.
- 130 '
- 140 ' To use, BLOAD the routine into any available free memory. It
- 150 ' has 2 entry points (INIT and GETNEXT). INIT (offset 2) is used
- 160 ' to define the disk drive (0=default, 1=A, 2=B, ....) and the
- 170 ' pattern to be used to match on. The pattern MUST BE a string of
- 180 ' length 11; the first 8 are the filename and the last 3 are the
- 190 ' extension. A "?" is used to match any character. For example to
- 200 ' get all the BASIC files on the disk, "????????BAS" would be used
- 210 ' as the input parameter. After INIT has been called, calls to
- 220 ' GETNEXT (offset 5) are made to retrieve matching file names.
- 230 ' The two parameters are the string in which the match is returned
- 240 ' (which must be of length 14) and an INTEGER (..%) return value.
- 250 ' If the status return is <0, no more matched have been found. If
- 260 ' status >=0, it is the FILE ATTRIBUTE (as defined in the DOS Disk
- 270 ' Directory).
- 280 '
- 290 ' A third entry point (CHMOD, offset 8) is provided to change the
- 300 ' file 'mode' bit. Three parameters are required; file name, new
- 310 ' mode (INTEGER) and status return (INTEGER).
- 320 '
- 330 ' The INTEGER value at offsets 0,1 in the routine are the offset
- 340 ' to the directory entry for the file. For example, to obtain the
- 350 ' DATE information of the file, use the following statements:
- 360 ' B% = PEEK(bload.base)+PEEK(bload.base+1)*256+BLOAD.BASE ' Get offset value
- 370 ' FDATE = PEEK(B%+26)*256 + PEEK(B%+25)
- 380 '
- 390 ' The offsets into the directory entry (25, 26 in this case) are
- 400 ' defined in the DOS manual.
- 410 '
- 420 ' The example program will list all the files on the default disk.
- 430 ' It will traverse all the directories on the disk and list the file
- 440 ' name and its attributes in HEX.
- 450 CLEAR ,&HF000 'setup area into which FCBREAD.BSV will be loaded
- 460 BLOAD.BASE=&HF000
- 470 BLOAD "fcbread.bsv",BLOAD.BASE 'load into area CLEARed by CLEAR command
- 480 INIT%=BLOAD.BASE+2:GETNEXT%=BLOAD.BASE+5 'entry point offsets take into account the base of BLOAD.
- 490 IMAX%=30:INEXT%=1
- 500 DIM DIR$(IMAX%)
- 510 CLS
- 520 CHDIR "\" 'start at the ROOT
- 530 CUR$=""
- 540 PAT$="???????????" 'match any file
- 550 DISK%=0:CALL INIT%(DISK%,PAT$)
- 560 FILENAME$=SPACE$(14):CALL GETNEXT%(FILENAME$,STATUS%)
- 570 IF STATUS%<0 THEN IF INEXT%>1 THEN INEXT%=INEXT%-1:CUR$=DIR$(INEXT%):CHDIR CUR$:GOTO 550 ELSE END
- 580 DISK$=LEFT$(FILENAME$,2):FILENAME$=MID$(FILENAME$,3)
- 590 IF (STATUS% AND &H10)=0 THEN GOTO 660 ' check for DIRECTORY
- 600 IF LEFT$(FILENAME$,1)="." THEN GOTO 560 'ignore "." entries
- 610 FILENAME$=LEFT$(FILENAME$,INSTR(FILENAME$,".")-1)
- 620 IF INEXT%>IMAX% THEN PRINT "Directory Stack Overflow":GOTO 560
- 630 DIR$(INEXT%)=CUR$+"\"+FILENAME$
- 640 INEXT%=INEXT%+1
- 650 GOTO 560
- 660 PRINT "x'"+HEX$(STATUS%)+"'" TAB(8) CUR$ "\" FILENAME$
- 670 GOTO 560
-